#include "Constant.hpp"

#include <cstring>

Constant::Constant ( int value )
{
    _value._class = CE_VALUE;
    _value._type._base = INTEGER;
    _value._type._modifier = NONE;
    _value._type._size = 0;
    _value._value._vinteger = value;
}

Constant::Constant ( float value )
{
    _value._class = CE_VALUE;
    _value._type._base = REAL;
    _value._type._modifier = NONE;
    _value._type._size = 0;
    _value._value._vreal = value;
}

Constant::Constant ( bool value )
{
    _value._class = CE_VALUE;
    _value._type._base = BOOLEAN;
    _value._type._modifier = NONE;
    _value._type._size = 0;
    _value._value._vboolean = value;
}

Constant::Constant ( const char* value )
{
    _value._class = CE_VALUE;
    _value._type._base = STRING;
    _value._type._modifier = NONE;
    _value._type._size = 0;
    _value._value._vstring = strdup ( value );
}

void
Constant::compute ()
{
  LOGFUNCTION ( IEXEC_LOG );
}

void
Constant::display ( const unsigned int shift ) const
{
    std::string vstring;
    switch ( _value._type._base )
    {
    case INTEGER:
        std::cout << _value._value._vinteger;
        break;
    case REAL:
        std::cout << _value._value._vreal;
        break;
    case BOOLEAN:
        std::cout << _value._value._vboolean;
        break;
    case STRING:
        vstring = "";
        for ( unsigned int i = 0 ; i < strlen ( _value._value._vstring ) ; i ++ )
            if ( _value._value._vstring [ i ] == '\n' )
                vstring += "\\n";
            else
                vstring += _value._value._vstring [ i ];
        std::cout << "\"" << vstring << "\"";
        break;
    default:
        break;
    }
}
